﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Entity.Car_Rental
{
    public partial class Category : Entity.EntityBase
    {
        public override object[] PrimaryKey
        {
            get { return new object[] { this.ID }; }
        }

        public override IEnumerable<RuleViolation> GetRuleViolations()
        {
            if (string.IsNullOrEmpty(this.Name))
                yield return new RuleViolation("不能为空", "Name");
            if (!this.ParentID.HasValue)
                yield return new RuleViolation("不能为空", "ParentID");

        }

        partial void OnCreated()
        {
            if (this.IsValid)//实体是否验证通过
            {
                base.Initialization();//基类的某些属性初始化
                this.PropertyChanged += new PropertyChangedEventHandler(base.PropertyChangedEvent);//初始实体时，先订阅列修改的事件
            }
        }
        #region 导航属性
        public Category Father { get; set; }
        public List<Category> Sons { get; set; }
        public static readonly int RootID = 1;
        #endregion
    }
}
